package config

import (
	"fmt"
	"strings"
)

func NewManager() *Manager {
	return &Manager{
		data: make(map[string]interface{}),
	}
}

type Manager struct {
	data map[string]interface{}
}

func (cm *Manager) LoadFromFile(filePath string) error {
	ext := strings.ToLower(filePath[strings.LastIndex(filePath, ".")+1:])

	switch ext {
	case "toml":
		return cm.loadTOML(filePath)
	case "yaml", "yml":
		return cm.loadYAML(filePath)
	case "json":
		return cm.loadJSON(filePath)
	case "ini":
		return cm.loadINI(filePath)
	default:
		return fmt.Errorf("unsupported file format: %s", ext)
	}
}
func (cm *Manager) Get(key string) (interface{}, bool) {
	value, ok := cm.data[key]
	return value, ok
}
